package com.ww.learn.oop.constructor

class InitOrderDemo(name: String) {
    val firstProperty = "First property: $name".also(::println)

    /**
     * 如果要在对象创建期间运行一些代码，请使用 init 块。
     */
    init {
        println("First initializer block that prints $name")
    }

    val sendProperty = "Second property: ${name.length}".also(::println)

    init {
        println("Second initializer block that prints ${name.length}")
    }
}

// 打印结果
//First property: hello
//First initializer block that prints hello
//Second property: 5
//Second initializer block that prints 5
fun main() {
    InitOrderDemo("hello")
}